$(document).ready(function() {
	if ($("#style").length > 0) {
		scheduleLoader($("#style").val());
		$("#delete").hide();
	}
});

$(document).delegate(
		'#style',
		'change',
		function() {
			if (($("#style").val() == "Box.Style")
					|| ($("#style").val() == "Table.Style")) {
				$("#delete").hide();
			} else {
				$("#delete").show();
			}
			$("#delete-error").html("");
			scheduleLoader($("#style").val());
		});

function scheduleLoader(style) {
	$.ajax({
		type : "POST",
		url : $("#project-base").val() + 'Users',
		async : true,
		data : "action=" + $("#action").val() + "&style=" + style,
		success : function(msg) {
			$("#schedule-box").html(msg);
			$(".m").each(function() {
				if ($(this).html() == "") {
					$(this).removeClass("m").addClass("m-1");
				}
			});
		},
		error : function(msg) {
			$("#schedule-box").html("<br /><center><h3>couldn't load schedule style try a different style</h3></center>");
		}
	});
}

function deleteStyle() {
	$.ajax({
		type : "POST",
		url : $("#project-base").val() + 'Users',
		async : true,
		data : "action=" + $("#delete-action").val() + "&style="
				+ $("#style").val(),
		success : function(msg) {
			alert("Style has been deleted");
			window.location.reload();
		},
		error : function(msg) {
			$("#delete-error").html("Couldn't delete file");
		}
	});
}


function upload() {
	$("#content").html("<h1>Uploading file, please wait...</h1>")
}